package psn.kiko.config.mybatis.plugin.executor;

import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;
import org.springframework.stereotype.Component;

/**
 * mybatis修改监测拦截器
 */
@Component
@Slf4j
@Intercepts(@Signature(
		type = Executor.class,
		method = "update",
		args = {MappedStatement.class,Object.class}
))
public class ExecutorUpdatePlugin implements Interceptor{
	@Override
	public Object intercept(Invocation invocation) throws Throwable{
		log.info("-------------->SQL更新插件开始运行");
		Object[] args = invocation.getArgs();
		log.debug("SQL入参列表：{}",invocation.getArgs()[1]);
		long cur = System.currentTimeMillis();
		Object r = invocation.proceed();
		log.debug("SQL执行耗时：{} ms",System.currentTimeMillis()-cur);
		log.info("<--------------SQL更新插件结束运行");
		return r;
	}
}
